package com.ucenter.server.org.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.system.comm.model.Page;
import com.system.handle.model.ResponseCode;
import com.system.handle.model.ResponseFrame;
import com.ucenter.server.org.dao.PositionRoleDao;
import com.ucenter.server.org.pojo.PositionRole;
import com.ucenter.server.org.service.PositionRoleService;

/**
 * position_role的Service
 * @author autoCode
 * @date 2018-12-01 09:50:14
 * @version V1.0.0
 */
@Component
public class PositionRoleServiceImpl implements PositionRoleService {

	@Autowired
	private PositionRoleDao positionRoleDao;
	
	@Override
	public ResponseFrame save(PositionRole positionRole) {
		ResponseFrame frame = new ResponseFrame();
		PositionRole org = get(positionRole.getPositionId(), positionRole.getRoleId());
		if(org == null) {
			positionRoleDao.save(positionRole);
		}
		frame.setCode(ResponseCode.SUCC.getCode());
		return frame;
	}

	@Override
	public PositionRole get(String positionId, String roleId) {
		return positionRoleDao.get(positionId, roleId);
	}

	@Override
	public ResponseFrame pageQuery(PositionRole positionRole) {
		positionRole.setDefPageSize();
		ResponseFrame frame = new ResponseFrame();
		int total = positionRoleDao.findPositionRoleCount(positionRole);
		List<PositionRole> data = null;
		if(total > 0) {
			data = positionRoleDao.findPositionRole(positionRole);
		}
		Page<PositionRole> page = new Page<PositionRole>(positionRole.getPage(), positionRole.getSize(), total, data);
		frame.setBody(page);
		frame.setCode(ResponseCode.SUCC.getCode());
		return frame;
	}
	
	@Override
	public ResponseFrame delete(String positionId, String roleId) {
		ResponseFrame frame = new ResponseFrame();
		positionRoleDao.delete(positionId, roleId);
		frame.setCode(ResponseCode.SUCC.getCode());
		return frame;
	}

	@Override
	public List<PositionRole> findByPositionId(String positionId) {
		return positionRoleDao.findByPositionId(positionId);
	}
}